home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 7336 / 7336.xpi / chrome / content / dwm-overlay.js next >
Text File  |  2009-11-25  |  5KB  |  175 lines

  1. /******************************************************************************
  2. Copyright 2008 Matthew Holder. All rights reserved.
  3.  
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6.  
  7.    1. Redistributions of source code must retain the above copyright notice,
  8. this list of conditions and the following disclaimer.
  9.    2. Redistributions in binary form must reproduce the above copyright notice,
  10. this list of conditions and the following disclaimer in the documentation
  11. and/or other materials provided with the distribution.
  12.  
  13. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  14. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  16. EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  18. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  20. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  21. OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  22. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *********************************************************************************/
  24. var glassTo = null;
  25. var inFullscreen = false;
  26. var dwm = Components.classes["@sixxgate.com/DwmCalls/CDwmCalls;1"].createInstance();
  27. dwm = dwm.QueryInterface(Components.interfaces.IDwmCalls);
  28.  
  29. function DWM_Glasser_OnFullscreen()
  30. {
  31.     this.handleEvent = function(e)
  32.     {
  33.         if (!dwm.GlassEnabled || glassTo == null)
  34.             // If no glass, we have nothing to do
  35.             return;
  36.  
  37.         if (e.attrName == "inFullscreen" && e.newValue == "true")
  38.         {
  39.             try
  40.             {
  41.                 dwm.ExtendFrameIntoWindow(0, 0, 0, 0);
  42.             }
  43.             catch (err)
  44.             {    // Something failed
  45.                 window.alert(err);
  46.             }
  47.             inFullscreen = true;
  48.         }
  49.         else if (e.attrName == "inFullscreen")
  50.         {
  51.             try
  52.             {
  53.                 var height = glassTo.boxObject.y + glassTo.boxObject.height;
  54.                 dwm.ExtendFrameIntoWindow(height, 0, 0, 0);
  55.             }
  56.             catch (err)
  57.             {    // Something failed
  58.                 window.alert(err);
  59.             }
  60.             inFullscreen = false;
  61.         }
  62.     }
  63. };
  64. var Glasser_OnFullscreen = new DWM_Glasser_OnFullscreen();
  65.  
  66. function DWM_Glasser_Delayed_OnAttrChange()
  67. {
  68.     this.handleEvent = function(e)
  69.     {
  70.         if (!dwm.GlassEnabled || glassTo == null || inFullscreen == true)
  71.             // If no glass, we have nothing to do
  72.             return;
  73.  
  74.         var height = glassTo.boxObject.y + glassTo.boxObject.height;
  75.  
  76.         try
  77.         {
  78.             dwm.ExtendFrameIntoWindow(height, 0, 0, 0);
  79.         }
  80.         catch (err)
  81.         {    // Something failed
  82.             window.alert(err);
  83.         }
  84.  
  85.         e.currentTarget.removeEventListener("DOMAttrModified", this, false);
  86.     };
  87. };
  88. var Glasser_Delayed_OnAttrChange = new DWM_Glasser_Delayed_OnAttrChange();
  89.  
  90. function ChangeGlasserTheme()
  91. {
  92.     if (dwm.GlassEnabled)
  93.     {
  94.         for (var i = 0; i != window.document.styleSheets.length; ++i)
  95.         {
  96.             if (window.document.styleSheets[i].href == "chrome://glasser/skin/overlay.css")
  97.             {
  98.                 window.document.styleSheets[i].disabled = false;
  99.                 break;
  100.             }
  101.         }
  102.         Glasser_Delayed_OnAttrChange.handleEvent(e);
  103.     }
  104.     else
  105.     {
  106.         for (var i = 0; i != window.document.styleSheets.length; ++i)
  107.         {
  108.             if (window.document.styleSheets[i].href == "chrome://glasser/skin/overlay.css")
  109.             {
  110.                 window.document.styleSheets[i].disabled = true;
  111.                 break;
  112.             }
  113.         }
  114.     }
  115. };
  116.  
  117. function DWM_Glasser_OnAttrChange()
  118. {
  119.     this.handleEvent = function(e)
  120.     {
  121.         e.currentTarget.addEventListener("DOMAttrModified", Glasser_Delayed_OnAttrChange, false);
  122.     };
  123. };
  124. var Glasser_OnAttrChange = new DWM_Glasser_OnAttrChange();
  125.  
  126. function DWM_Glasser_OnLoad()
  127. {
  128.     this.handleEvent = function(e)
  129.     {
  130.         // Find the toolbar marked as glassToMe
  131.         var toolbox = window.document.getElementById("navigator-toolbox")
  132.         if (toolbox == null)
  133.             return;
  134.             
  135.         toolbox.addEventListener("DOMAttrModified", Glasser_OnFullscreen, false);
  136.  
  137.         var ct = toolbox.firstChild;
  138.         var breakNow = false;
  139.         for (; ct != null; ct = ct.nextSibling)
  140.         {
  141.             if (ct.tagName != "toolbar")
  142.                 // Only toolbar are of any concern
  143.                 continue;
  144.  
  145.             ct.addEventListener("DOMAttrModified", Glasser_OnAttrChange, false);
  146.  
  147.             if (breakNow)
  148.                 // We have attatched to the last toolbar, we are done
  149.                 break;
  150.  
  151.             if (ct.getAttribute("glassToMe") != null && ct.getAttribute("glassToMe") == "true")
  152.             {    // We have found the end of the glass, break on the next toolbar
  153.                 glassTo = ct;
  154.                 breakNow = true;
  155.             }
  156.         }
  157.         
  158.         ChangeGlasserTheme();
  159.     };
  160. };
  161. var Glasser_OnLoad = new DWM_Glasser_OnLoad();
  162.  
  163. function DWM_Glasser_OnGlassChange()
  164. {
  165.     this.handleEvent = function(e)
  166.     {
  167.         ChangeGlasserTheme();
  168.     };
  169. };
  170. var Glasser_OnGlassChange = new DWM_Glasser_OnGlassChange();
  171.  
  172. window.addEventListener("load", Glasser_OnLoad, false);
  173.  
  174. dwm.AttachToWindow(window);
  175. dwm.OnGlassChange = Glasser_OnGlassChange;